package com.group.mall.controller;

import com.group.mall.domain.POJO.GoodsPro;
import com.group.mall.domain.POJO.ShoppingCart;
import com.group.mall.domain.VO.ShoppingCartVO;
import com.group.mall.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService  shoppingCartService;

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list/{userId}")
    public List<ShoppingCart> list(@PathVariable("userId") Integer userId){
        List<ShoppingCart> shoppingCartList = shoppingCartService.showShoppingCart(userId);
        return shoppingCartList;
    }

    @GetMapping("/goodsprolist")
    public List<GoodsPro> showGoodsPro(Integer goodsId ){
        List<GoodsPro> goodsProList=shoppingCartService.showGoodsPro(goodsId);
        return goodsProList;
    }

    /**
     * 根据id删除商品
     * @param id
     */
    @GetMapping("/delete")
    public void delete(Long id){
        log.info("删除购物车商品id为:{}",id);
        shoppingCartService.deleteById(id);
    }

    @GetMapping("/add")
    public void add(Long id){
        log.info("商品id:{}",id);
        shoppingCartService.add(id);
    }

    @GetMapping("/sub")
    public void sub(Long id){
        log.info("商品id:{}",id);
        shoppingCartService.sub(id);
    }

    @PostMapping("/update1")
    public void updatecart(ShoppingCartVO shoppingCartVO){
        shoppingCartService.updatecart(shoppingCartVO);
    }
}